import java.awt.Graphics;
import java.awt.Point;
import java.awt.Shape;
import java.awt.geom.Ellipse2D;

public class PLEllipse extends PLShape {
	private static final long serialVersionUID = 1L;
	public PLEllipse() {		
		super(ShapeIdT.kEllipse);
	}		
	
	public PLEllipse(Point start, Point end){		
		super(ShapeIdT.kEllipse);
		Parse(start, end);
	}		

	// Attributes 
	public float GetWidth() { 
		return Math.abs((mStart.x - mEnd.x));
	}
	public float GetHeight() { 
		return Math.abs((mStart.y - mEnd.y)); 
	}
	public float GetArea() { return (float)Math.PI * (GetWidth() * GetHeight())/4; }	
	
	public Shape GetJavaShape(){
		return new Ellipse2D.Float(mStart.x, mStart.y, GetWidth(), GetHeight()); 
	}

	public boolean IsCircle() { return (GetWidth() == GetHeight());}

	
	
	public PLLine GetInitialDrawLine(){
		PLLine line = new PLLine(mStart,mEnd);
		return line;
	}
		
	// Draw
	public void Draw(Graphics g) {
		PLDebug.Info("Trying to draw Ellipse"); 
		//Point drawto = new Point( Math.max(mEnd.x,mStart.x),Math.max(mEnd.y,mStart.y));
		Point newstart = new Point(Math.min(mEnd.x,mStart.x),Math.min(mEnd.y,mStart.y));
		try	{
			g.drawOval(newstart.x, newstart.y, (int)GetWidth(), (int)GetHeight() ); 
		}
		catch (NullPointerException e) {
			System.out.println("Null Pointer: Nothing to draw"); 
		}		
	}





	// PROTECTED
	protected void SetupLines() {	
		mLines = new PLLine[4];	
		Point[] corners = GetCorners();
	
		mLines[0] = new PLLine(corners[0], corners[1]);
		mLines[1] = new PLLine(corners[1], corners[2]);
		mLines[2] = new PLLine(corners[2], corners[3]);
		mLines[3] = new PLLine(corners[3], corners[0]);		
	}
	
	protected void SetupCorners() {
		mCorners = new Point[4]; 
		
		Point start = new Point(Math.min(mEnd.x,mStart.x),Math.min(mEnd.y,mStart.y));
		
		mCorners[0] = new Point(start); 
		mCorners[1] = new Point((int)(start.x + GetWidth()), start.y);
		mCorners[2] = new Point((int)(start.x + GetWidth()), (int)(start.y + GetHeight()));
		mCorners[3] = new Point(start.x, (int)(start.y + GetHeight()));
	}	

}
	
	

